<?php
/**
 * 控制器基本类，其它控制器类继承它
 *
 */
class Base {

	public  function _config($ctrl,$mod) {
		static $_CfgList;
		$key=$mod."_".$ctrl;
		if (!isset($_CfgList)) {
			$_CfgList=array();
		}
		if (!isset($_CfgList[$key])) {

		}
	}

	public function redirect($message=null, $url = null,$isFail=true) {
		if ($message) {
			$messageTmp="<font color=red >".$message."</font>";
			if ($isFail==false) {
				$messageTmp="<font color=green >".$message."</font>";
			}
			$message=$messageTmp;
		}
		if (isset($url)) {
			$mes = "";
			if (isset($message)) {
				$mes = "&message=";
			}
			$url=array($url.$mes);
			$id="";
		} else if (isset($message)) {
			preg_replace('/[&|?]+id=[A-Za-z0-9]*/', "", $_SERVER['HTTP_REFERER']);

			if (preg_match('/&/', $_SERVER['HTTP_REFERER']) > 0) {
				$message = "&message=".$message;
				$url = preg_split('/(&||\?)message=[A-Za-z0-9]*/', $_SERVER['HTTP_REFERER']);
			} else {
				$message = "?message=".$message;
			}

			if (isset($_REQUEST['id']) && !empty($_REQUEST['id']) && !is_array($_REQUEST['id'])) {
				$id = "&id=".$_REQUEST['id'];
			} else {
				$id="";
			}
		} else {
			if (isset($_REQUEST['id']) && !empty($_REQUEST['id']) && (preg_match('/&/', $_SERVER['HTTP_REFERER']) > 0)) {
				$id = "&id=".$_REQUEST['id'];
			} else if (preg_match('/&/', $_SERVER['HTTP_REFERER']) == 0){
				$id = "?id=".$_REQUEST['id'];
			} else {
				$id="";
			}
		}

		header("Location: ".$url[0].$message.$id);
	}
}